递归：
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    bool check(TreeNode* left, TreeNode* right) {
        if (left == nullptr && right == nullptr) {
            return true;
        } else if ((left == nullptr && right != nullptr) || 
                (left != nullptr && right == nullptr)) {
                    return false;
        } else {
            if (left->val != right->val) {
                return false;
            } else {
                return (check(left->left, right->right) == true) &&
                        (check(left->right, right->left) == true);
            }
        }
                
    }
    bool isSymmetric(TreeNode* root) {
        if (root == nullptr) {
            return true;
        } else {
            return check(root->left, root->right);
        }
    }
};


迭代：
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    bool check(TreeNode* l, TreeNode* r) {
        queue <TreeNode*> q;
        q.push(l);
        q.push(r);
        while (!q.empty()) {
            l = q.front();
            q.pop();
            r = q.front();
            q.pop();
            if (!l && !r) continue;
            if ((!l || !r) || (l->val != r->val)) {
                return false;
            } else {
                q.push(l->left);
                q.push(r->right);
                q.push(l->right);
                q.push(r->left);
            }
        }
        return true;

    }
    bool isSymmetric(TreeNode* root) {
        return check(root, root);
    }
};